package com.mall.controller;

import com.domain.OrderMall;
import com.domain.result.ResultData;
import com.service.seinterface.OrderService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mall")
public class OrderController {

    @Resource
    OrderService orderService;
    /**
     * 添加订单
     * @param orderMall
     * @param
     * @return
     */
    @RequestMapping("/addOrder")
    public ResultData addOrder(@RequestBody OrderMall orderMall){
        return orderService.addOrder(orderMall, orderMall.getOrderGoods());
    }

    /**
     * 获取用户订单列表
     * @param userid
     * @return
     */
    @RequestMapping("/getOrderByUserId")
    public ResultData getOrderByUserId(Integer userid){
        return orderService.getOrderByUserId(userid);
    }

    /**
     * 获取用户订单列表
     * @param userid
     * @return
     */
    @RequestMapping("/getOrderByUserIdAndOrderType")
    public ResultData getOrderByUserIdAndOrderType(Integer userid,Integer ordetype){
        return orderService.getOrderByUserIdAndOrderType(userid,ordetype,null,null);
    }

    /**
     * 删除用户订单
     * @param orderid
     * @return
     */
    @RequestMapping("/deleteOrderById")
    public ResultData deleteOrderById(Integer orderid){
        return orderService.deleteOrderById(orderid);
    }


    /**
     * 修改订单状态
     * @param orderid
     * @param state
     * @param ordertype
     * @return
     */
    @RequestMapping("/updateOrderState")
    public ResultData updateOrderState(Integer orderid,Integer state,Integer ordertype){
        return orderService.updateOrderState(orderid,state,ordertype);
    }

    /**
     * 根据订单类型获取订单
     * @param ordertype
     * @param orderstate 1表示未完成 2表示完成或取消
     * @return
     */
    @RequestMapping("/getOrdersByOrderType")
    public ResultData getOrderByOrderType(Integer ordertype,Integer orderstate){
        return orderService.getOrderByOrderType(ordertype,orderstate);
    }


}
